﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Windows.Documents;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using ReportingFramework;
using WorkItemReportInterface;

namespace MSFforAgileSoftwareDevelopmentv50Basic
{
  /// <summary>
  /// Interaction logic for MSFforAgileSoftwareDevelopmentv50BasicTemplate.xaml
  /// </summary>
  [Export(typeof(IWorkItemReport))]
  public partial class MSFforAgileSoftwareDevelopmentv50BasicTemplate : Report, IWorkItemReport
  {
    public MSFforAgileSoftwareDevelopmentv50BasicTemplate()
    {
      InitializeComponent();
    }

    public ReportType ProcessTemplate
    {
      get { return ReportType.MSFforAgileSoftwareDevelopmentv50; }
    }

    public string Description
    {
      get { return "MSF for Agile Software Development v5.0 Basic Report"; }
    }

    public FixedDocument Create(IEnumerable<WorkItem> data)
    {
      var rows = new List<object>();
      foreach (var workItem in data)
      {
        switch (workItem.Type.Name)
        {
            case "User Story":
                rows.Add(new ProductBacklogItemCardRow(workItem));
                break;
            case "Task":
                rows.Add(new TaskCardRow(workItem));
                break;
            case "Bug":
                rows.Add(new BugCardRow(workItem));
                break;
            default:
                rows.Add(new UnknownCardRow(workItem));
                break;
        }
      }

      return GenerateReport(
        page => new PageInfo(page, DateTime.Now),
        rows
        );
    }

    /// <summary>
    /// This class becomes the data context for every page. It gives the page 
    /// access to the page number.
    /// </summary>
    public class PageInfo
    {
      public PageInfo(int pageNumber, DateTime reportDate)
      {
        PageNumber = pageNumber;
        ReportDate = reportDate;
      }

      public bool IsFirstPage { get { return PageNumber == 1; } }
      public int PageNumber { get; set; }
      public DateTime ReportDate { get; set; }
    }
  }
}
